<?php
/**
 * metodopago actions.
 *
 * @package    courier
 * @subpackage metodopago
 * @author     
 */
class metodopagoActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->Metodopagos = MetodopagoPeer::doSelect(new Criteria());
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->Metodopago = MetodopagoPeer::retrieveByPk($request->getParameter('met_id'));
    $this->forward404Unless($this->Metodopago);
  }

  public function executeShowTarjeta(sfWebRequest $request)
  {
    $this->Cliente = ClientePeer::retrieveByPk($request->getParameter('cli_id'));
    $this->forward404Unless($this->Cliente);
  }

  public function executeNew(sfWebRequest $request)
  {
	if ($request->getParameter('cli_id') != null){
		$identificadorCliente = new Metodopago();
		$identificadorCliente->setMetCliente($request->getParameter('cli_id'));
		$this->form = new MetodopagoForm($identificadorCliente);
	}
	else{
		$this->form = new MetodopagoForm();
	}
  }

  public function executeNewMetodoCliente(sfWebRequest $request)
  {
	if ($request->getParameter('cli_id') != null){
		$identificadorCliente = new Metodopago();
		$identificadorCliente->setMetCliente($request->getParameter('cli_id'));
		$this->form = new MetodopagoForm($identificadorCliente);
	}
	else{
		$this->form = new MetodopagoForm();
	}
  }  

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new MetodopagoForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($Metodopago = MetodopagoPeer::retrieveByPk($request->getParameter('met_id')), sprintf('Object Metodopago does not exist (%s).', $request->getParameter('met_id')));
    $this->form = new MetodopagoForm($Metodopago);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($Metodopago = MetodopagoPeer::retrieveByPk($request->getParameter('met_id')), sprintf('Object Metodopago does not exist (%s).', $request->getParameter('met_id')));
    $this->form = new MetodopagoForm($Metodopago);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');

   
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($Metodopago = MetodopagoPeer::retrieveByPk($request->getParameter('met_id')), sprintf('Object Metodopago does not exist (%s).', $request->getParameter('met_id')));

    $cli_id = $Metodopago->getMetCliente();

    $Metodopago->delete();

    $this->redirect('metodopago/showTarjeta?cli_id='.$cli_id);
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $Metodopago = $form->save();

      $this->redirect('metodopago/showTarjeta?cli_id='.$request->getParameter('metodopago[met_cliente]'));
    }
  }
}
